﻿using System;
using System.Collections.Generic;
using Microsoft.Practices.ServiceLocation;

namespace Zeus.Interop.SampleSite.Stubs
{
    public class ServiceLocator : IServiceLocator
    {
        // Stubbed Method to mimic IoC
        public static T GetService<T>()
        {
            return new ServiceLocator().GetInstance<T>();
        }

        public object GetService(Type serviceType)
        {
            if (serviceType == typeof(IRepository))
                return new StaticData();

            if (serviceType == typeof(ICustomerService))
                return new CustomerService();

            if(serviceType == typeof(IProductService))
                    return new ProductService();

            return null;
        }

        public object GetInstance(Type serviceType)
        {
            return GetService(serviceType);
        }

        public object GetInstance(Type serviceType, string key)
        {
            return GetService(serviceType);
        }

        public IEnumerable<object> GetAllInstances(Type serviceType)
        {
            yield return GetService(serviceType);
        }

        public TService GetInstance<TService>()
        {
            return (TService)GetService(typeof(TService));
        }

        public TService GetInstance<TService>(string key)
        {
            return GetInstance<TService>();
        }

        public IEnumerable<TService> GetAllInstances<TService>()
        {
            yield return GetInstance<TService>();
        }
    }
}